package com.runvp.rest.biz;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.runvp.common.annotation.Log;
import com.runvp.common.enums.BusinessType;
import com.runvp.service.biz.domain.BizAppVersion;
import com.runvp.service.biz.service.IBizAppVersionService;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.utils.poi.ExcelUtil;
import com.runvp.common.annotation.ParamValid;
import com.runvp.common.core.page.TableDataInfo;

/**
 * APP版本Controller
 * 
 * @author runvp
 * @date 2023-03-20
 */
@Controller
@RequestMapping("/biz/version")
public class BizAppVersionController extends BaseController {
    private String prefix = "biz/version";

    @Autowired
    private IBizAppVersionService bizAppVersionService;

    @RequiresPermissions("biz:version:view")
    @GetMapping()
    public String version() {
        return prefix + "/version";
    }

    /**
     * 查询APP版本列表
     */
    @RequiresPermissions("biz:version:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizAppVersion bizAppVersion) {
        startPage();
        List<BizAppVersion> list = bizAppVersionService.selectBizAppVersionList(bizAppVersion);
        return getDataTable(list);
    }

    /**
     * 导出APP版本列表
     */
    @RequiresPermissions("biz:version:export")
    @Log(title = "APP版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizAppVersion bizAppVersion) {
        List<BizAppVersion> list = bizAppVersionService.selectBizAppVersionList(bizAppVersion);
        ExcelUtil<BizAppVersion> util = new ExcelUtil<BizAppVersion>(BizAppVersion.class);
        return util.exportExcel(list, "APP版本数据");
    }

    /**
     * 新增APP版本
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存APP版本
     */
    @ParamValid
    @RequiresPermissions("biz:version:add")
    @Log(title = "APP版本", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizAppVersion bizAppVersion) {
        return toAjax(bizAppVersionService.insertBizAppVersion(bizAppVersion));
    }

    /**
     * 修改APP版本
     */
    @RequiresPermissions("biz:version:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        BizAppVersion bizAppVersion = bizAppVersionService.selectBizAppVersionById(id);
        mmap.put("bizAppVersion", bizAppVersion);
        return prefix + "/edit";
    }
    /**
     * APP版本详情
     */
    @RequiresPermissions("biz:version:edit")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap) {
        BizAppVersion bizAppVersion = bizAppVersionService.selectBizAppVersionById(id);
        mmap.put("bizAppVersion", bizAppVersion);
        return prefix + "/detail";
    }
    /**
     * 修改保存APP版本
     */
    @ParamValid
    @RequiresPermissions("biz:version:edit")
    @Log(title = "APP版本", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizAppVersion bizAppVersion) {
        return toAjax(bizAppVersionService.updateBizAppVersion(bizAppVersion));
    }

    /**
     * 删除APP版本
     */
    @RequiresPermissions("biz:version:remove")
    @Log(title = "APP版本", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bizAppVersionService.deleteBizAppVersionByIds(ids));
    }
}
